import {
  fetchSearchOrder,
  fetchListMyOrder,
  fetchOrderDetail,
  fakeEnterOrder,
  fetchCheckUserInfo,
  fakeRechargeOrder,
  fakeExportUserOrder,
  fakeCheckOrder,
  fakeCheckOrderRecharge,
  fetchSearchToRechargeOrder,
  fetchSearchMyRechargeOrder,
  fetchSearchToCheckRecharge,
  fetchSearchToCheckOrder,
} from '@/services/OrderServices';
import { notification } from 'antd';
export default {
  namespace: 'order',
  state: {
    list: { list: [], total: 0 },
    orderList: { list: [], total: 0 },
    myOrderList: { list: [], total: 0 },
    toCheckList: { list: [], total: 0 },
    myCheckList: { list: [], total: 0 },
    orderRechargeList: { list: [], total: 0 },
    orderCheckList: { list: [], total: 0 },
  },
  effects: {
    *fetchSearchToCheckRecharge({ payload, callback }, { call, put }) {
      const response = yield call(fetchSearchToCheckRecharge, payload);
      if (!response) return;
      const { orderRechargeList, total } = response.content;
      yield put({
        type: 'save',
        payload: {
          orderRechargeList: {
            list: orderRechargeList,
            total,
          },
        },
      });
    },
    *fetchSearchToCheckOrder({ payload, callback }, { call, put }) {
      const response = yield call(fetchSearchToCheckOrder, payload);
      if (!response) return;
      const { orderList, total } = response.content;
      yield put({
        type: 'save',
        payload: {
          orderCheckList: {
            list: orderList,
            total,
          },
        },
      });
    },
    *fetchListMyOrder({ payload, callback }, { call, put }) {
      const response = yield call(fetchListMyOrder, payload);
      if (!response) return;
      const { orderList, total } = response.content;
      yield put({
        type: 'save',
        payload: {
          myOrderList: {
            list: orderList,
            total,
          },
        },
      });
    },
    *fetchSearchToRechargeOrder({ payload, callback }, { call, put }) {
      const response = yield call(fetchSearchToRechargeOrder, payload);
      if (!response) return;
      const { orderList, total } = response.content;
      yield put({
        type: 'save',
        payload: {
          toCheckList: {
            list: orderList,
            total,
          },
        },
      });
    },
    *fetchSearchMyRechargeOrder({ payload, callback }, { call, put }) {
      const response = yield call(fetchSearchMyRechargeOrder, payload);
      if (!response) return;
      const { orderList, total } = response.content;
      yield put({
        type: 'save',
        payload: {
          myCheckList: {
            list: orderList,
            total,
          },
        },
      });
    },

    *fetchSearchOrder({ payload, callback }, { call, put }) {
      const response = yield call(fetchSearchOrder, payload);
      if (!response) return;
      const { orderList, total } = response.content;
      yield put({
        type: 'save',
        payload: {
          orderList: {
            list: orderList,
            total,
          },
        },
      });
    },
    *fetchCheckUserInfo({ payload, callback }, { call, put }) {
      const response = yield call(fetchCheckUserInfo, payload);
      if (!response) return;
      callback && callback(response.content)
    },
    *fetchCheckUserInfo({ payload, callback }, { call, put }) {
      const response = yield call(fetchCheckUserInfo, payload);
      if (!response) return;
      callback && callback(response.content)
    },
    *fetchOrderDetail({ payload, callback }, { call, put }) {
      const response = yield call(fetchOrderDetail, payload);
      if (!response) return;
      callback && callback(response.content)
    },
    *fakeEnterOrder({ payload, callback }, { call, put }) {
      const response = yield call(fakeEnterOrder, payload);
      if (!response) return;
      notification.success({
        message: '温馨提示',
        description: '提交成功',
      });
      callback && callback(response.content)
    },
    *fakeRechargeOrder({ payload, callback }, { call, put }) {
      const response = yield call(fakeRechargeOrder, payload);
      if (!response) return;
      notification.success({
        message: '温馨提示',
        description: '提交成功',
      });
      callback && callback(response.content)
    },
    *fakeExportUserOrder({ payload, callback }, { call, put }) {
      const response = yield call(fakeExportUserOrder, payload);
      if (!response) return;
      notification.success({
        message: '温馨提示',
        description: '导出成功',
      });
      callback && callback(response.content)
    },

    *fakeCheckOrder({ payload, callback }, { call, put }) {
      const response = yield call(fakeCheckOrder, payload);
      if (!response) return;
      notification.success({
        message: '温馨提示',
        description: '提交成功',
      });
      callback && callback(response.content)
    },


    *fakeCheckOrderRecharge({ payload, callback }, { call, put }) {
      const response = yield call(fakeCheckOrderRecharge, payload);
      if (!response) return;
      notification.success({
        message: '温馨提示',
        description: '提交成功',
      });
      callback && callback(response.content)
    },

  

  },



  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
